/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.config.HkSystemExchangeBooth;
import com.thinkgem.jeesite.modules.hk.sys.service.config.HkSystemExchangeBoothService;

/**
 * 展示商品金币设置Controller
 * @author 罗天文
 * @version 2018-06-21
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/config/hkSystemExchangeBooth")
public class HkSystemExchangeBoothController extends BaseController {

	@Autowired
	private HkSystemExchangeBoothService hkSystemExchangeBoothService;
	
	@ModelAttribute
	public HkSystemExchangeBooth get(@RequestParam(required=false) String id) {
		HkSystemExchangeBooth entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkSystemExchangeBoothService.get(id);
		}
		if (entity == null){
			entity = new HkSystemExchangeBooth();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:config:hkSystemExchangeBooth:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkSystemExchangeBooth hkSystemExchangeBooth, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkSystemExchangeBooth> page = hkSystemExchangeBoothService.findPage(new Page<HkSystemExchangeBooth>(request, response), hkSystemExchangeBooth); 
		model.addAttribute("page", page);
		return "hk/sys/config/hkSystemExchangeBoothList";
	}

	@RequiresPermissions("sys:config:hkSystemExchangeBooth:view")
	@RequestMapping(value = "form")
	public String form(HkSystemExchangeBooth hkSystemExchangeBooth, Model model) {
		model.addAttribute("hkSystemExchangeBooth", hkSystemExchangeBooth);
		return "hk/sys/config/hkSystemExchangeBoothForm";
	}

	@RequiresPermissions("sys:config:hkSystemExchangeBooth:edit")
	@RequestMapping(value = "save")
	public String save(HkSystemExchangeBooth hkSystemExchangeBooth, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkSystemExchangeBooth)){
			return form(hkSystemExchangeBooth, model);
		}
		hkSystemExchangeBoothService.save(hkSystemExchangeBooth);
		addMessage(redirectAttributes, "保存展示商品金币设置成功");
		return "redirect:"+Global.getAdminPath()+"/sys/config/hkSystemExchangeBooth/?repage";
	}
	
	@RequiresPermissions("sys:config:hkSystemExchangeBooth:edit")
	@RequestMapping(value = "delete")
	public String delete(HkSystemExchangeBooth hkSystemExchangeBooth, RedirectAttributes redirectAttributes) {
		hkSystemExchangeBoothService.delete(hkSystemExchangeBooth);
		addMessage(redirectAttributes, "删除展示商品金币设置成功");
		return "redirect:"+Global.getAdminPath()+"/sys/config/hkSystemExchangeBooth/?repage";
	}

}